#ifndef SNACK_TRACK_H
#define SNACK_TRACK_H

#include "CuePoints.h"

#include <string>
#include <limits>

//double bob = std::numeric_limits<double>::max(); // MSVC has a macro called max(), which breaks this good max!!!

namespace SnackBreak
{

// Track interface class.
// The implementation will wrap FMOD calls fairly directly.
class Track
{
public:
	Track(std::string f, CuePair q)
	: 
		filePathName(f), 
		cueInfo(q)
	{};
	Track(std::string f, CuePair q, double lastBeatNum) 
	: 
		filePathName(f), 
		cueInfo(q)
    {};

	enum Mode 
	{
		Paused,
		Playing,
		CuePaused
	};
	
	// Set/get the current play position in beats.
	virtual void setPosition(double beatNumber = 0.0) const = 0;
	virtual double getPosition() const = 0 ;

	// Set the relative playback speed. Pass 1.0 for normal speed, 1.1 for +10% etc.
	virtual void setPlayRate(double rateMultiplier) const = 0;

	// Set the volume/fader/level/amplitude. Pass 1.0 for max, 0 for silent.
	virtual void setVolume(double vol) const = 0;

	// Determine if track is playing (true) or paused (false).
	virtual bool IsPlaying() const = 0;

	// Start or resume playback. (continues playing if already playing)
	virtual void Play() = 0;

	// Pause playback.
	virtual void Pause() = 0;

	// Enter Cue-Pause (CDJ-like frame loop for setting cue) mode.
	virtual void CuePause() = 0;

	// Nudge/jog the current cue pause frame forward by numFrames (or backward if negative)
	virtual void NudgeCuePause(int numFrames = 1) = 0;

	// Set simple CDJ-style single cue point, based on current play pos or cue-pause pos if in cue-pause mode.
	// (This sets up "beats" to equal seconds in the normal cue scheme.)
	virtual void SetSimpleCue() = 0;

    // Saves cue info to an xml file alongside the file. This file if present will be read when the file is next opened.
    virtual void AutoSaveCueInfo() = 0;
    
    // Loads cue info from an xml file alongside the file. 
    virtual void AutoLoadCueInfo() = 0;
    
	// (Convenience) Rewind to zero beat.
	void Rewind() const { setPosition(0.0); };

	// accessors
	virtual Mode getMode() const { return currentMode; };
	TrackCuePair getCueInfo() const { return cueInfo; };
	void setCueInfo(const TrackCuePair info) { cueInfo = info; };
	double getLastBeatNum() const { return cueInfo.lastBeatInTrack; };


protected:
	std::string filePathName;
	TrackCuePair cueInfo;
	Mode currentMode;
    
private:
};

}; // namespace SnackBreak

#endif // SNACK_TRACK_H
